package com.dhemery.mack.adapters.tests;

import static org.junit.Assert.*;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.junit.Test;

import com.dhemery.mack.adapters.NodeImageDescriptorFactory;
import com.dhemery.mack.adapters.NodeInformationProvider;
import com.dhemery.mack.adapters.tests.FakeImageDescriptor;
import com.dhemery.mack.model.Folder;
import com.dhemery.mack.model.Node;


public class NodeInformationProviderTests {

	@Test
	public void labelIsNodeName() {
		IWorkbenchAdapter provider = new NodeInformationProvider(null);
		Node node = new Node("arbitrary name");

		assertEquals(node.getName(), provider.getLabel(node));
	}

	@Test
	public void parentIsNodeFolder() {
		IWorkbenchAdapter provider = new NodeInformationProvider(null);
		Node node = new Node("irrelevant name");
		Folder folder = new Folder();
		folder.addNode(node);

		assertEquals(node.getFolder(), provider.getParent(node));
	}

	@Test
	public void childArrayIsEmpty() {
		IWorkbenchAdapter provider = new NodeInformationProvider(null);
		Node node = new Node("irrelevant name");

		assertEquals(0, provider.getChildren(node).length);
	}

	@Test
	public void imageDescriptorIsRetrievedFromFactory() {
		ImageDescriptor expected = new FakeImageDescriptor("the right image descriptor");
		NodeImageDescriptorFactory factory = new NodeImageDescriptorFactory(new FakeConstantImageDescriptorSource(expected));
		IWorkbenchAdapter provider = new NodeInformationProvider(factory);

		assertEquals(expected, provider.getImageDescriptor(new Folder()));
	}
}
